package com.icss.monitor.service.impl;

import com.icss.monitor.service.EmailService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

/**
 * @Author: Wings丶
 * @Description:
 * @Date: Created in 12:03 2019/1/2
 * @Modified By:
 */
@Component
public class EmailServiceImpl implements EmailService {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Value("${mail.fromMail.addr}")
    private String from;

    //spring提供的邮件发送类
    @Autowired
    private JavaMailSender mailSender;
    @Override
    public void sendSimpleEmail(String to, String subject, String content) {
        //创建简单邮件消息
        SimpleMailMessage message = new SimpleMailMessage();
        //设置发件人
        message.setFrom(from);
        //设置收件人
        message.setTo(to);

        /*
            同时发送给多人
        String[] adds = {"xxx@qq.com","xxx@qq.com"};
        message.setTo(adds);*/

        //设置主题
        message.setSubject(subject);
        //设置内容
        message.setText(content);

        try{
            mailSender.send(message);
            logger.info("Mail sends succeeded");
        } catch (Exception e){
            logger.error("Mail sends failed");
        }
    }

    @Override
    public void sendHtmlEmail(String to, String subject, String content) {

    }

    @Override
    public void sendAttachmentsEmail(String to, String subject, String content, String filePath) {

    }

    @Override
    public void sendInlineResourceEmail(String to, String subject, String content, String rscPath, String rscId) {

    }
}
